package com.example.teachingevaluationsystem.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.teachingevaluationsystem.entity.Course;
import com.example.teachingevaluationsystem.entity.User;
import com.example.teachingevaluationsystem.mapper.CourseMapper;
import com.example.teachingevaluationsystem.service.CourseService;
import com.example.teachingevaluationsystem.service.IUserService;
import com.example.teachingevaluationsystem.vo.CourseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * 课程 服务实现类
 *
 * @author lp
 * @since 2022-03-28
 */
@Service
public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> implements CourseService {

  @Autowired CourseMapper courseMapper;
  @Autowired IUserService userService;

  @Override
  public Page<CourseVo> pageVo(Page<Course> coursePage, Course course) {
    return courseMapper.selectPageVo(coursePage, course);
  }

  @Override
  public Page<CourseVo> loadCourseListByUserName(
      Page<CourseVo> courseVoPage, String name, Long planId) {
    return courseMapper.selectListByUserName(courseVoPage, name, planId);
  }

  @Override
  public Page<CourseVo> pageOrderVo(
      String name, Page<Course> coursePage, Course course, boolean isOrder) {
    final User user = userService.loadUserByUserName(name);
    if (isOrder) {
      // 执行已经订阅的查询
      return courseMapper.selectPageVoByOrder(coursePage, course, user.getId());
    }

    return courseMapper.selectPageVoNoOrder(coursePage, course, user.getId());
  }

  @Override
  public Page<CourseVo> loadCourseListByTeacherName(
      Page<CourseVo> courseVoPage, String name, Long planId) {
    return courseMapper.selectCourseListByTeacherName(courseVoPage, name, planId);
  }

  @Override
  public Page<CourseVo> loadEvaluationStatus(Page<CourseVo> courseVoPage, String name,Boolean isTeacher) {
    return courseMapper.selectStudentEvaluationStatus(courseVoPage,name);
  }
}
